package com.abel.bigwater.dataserver.model.qdies

import com.abel.bigwater.data.BcdString
import io.netty.buffer.Unpooled
import org.junit.Assert
import org.junit.Test
import org.slf4j.LoggerFactory
import java.net.InetSocketAddress

class MainIpPortDataTest {

    @Test
    fun fillSet() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.SetIpPort
            data = MainSetIpPortData().also {
                it.address = InetSocketAddress("192.168.1.15", 5001)
            }

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        Assert.assertEquals(DEMO_SET_IP_PORT, str)
    }

    @Test
    fun fillAsk() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.AskIpPort
            data = MainAskIpPortData()

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        Assert.assertEquals(DEMO_ASK_IP_PORT, str)
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(MainIpPortDataTest::class.java)

        const val DEMO_SET_IP_PORT = "68120000010606c0a8010f13896516"

        const val DEMO_ASK_IP_PORT = "681200000107007e16"
    }
}